package net.zjitc.servlet;

import net.zjitc.domain.Product;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @Author admin
 * @Date 2019/2/27 13:58
 */
@WebServlet(name = "UpdateProductUIServlet",urlPatterns = "/updateProductUI")
public class UpdateProductUIServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ProductService service = new ProductServiceImpl();
        String id = request.getParameter("pid");
//        int pid = Integer.parseInt(id);
        Product product = null;
        try {
            product = service.fingById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("p",product);
        request.getRequestDispatcher("/WEB-INF/edit.jsp").forward(request,response);
    }
}
